<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>购物车示例</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
    
    <div id="app" v-cloak>
        <template v-if="list.length">
            <table>
                <thead>
                    <tr>
                        <th><input type="checkbox" @click="handleSelectAll()" :checked="selectAll"></th>
                        <th>商品编号</th>
                        <th>商品名称</th>
                        <th>商品单价</th>
                        <th>购买数量</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <template v-for="(itemOut, indexOut) in list">
                        <tr><td colspan="6" style="text-align: center;">{{ itemOut.classify }}</td></tr>
                        <tr v-for="(itemIn,indexIn) in itemOut.datas">
                                <td><input type="checkbox" @click="handleSelect(indexOut,indexIn)" :checked="itemIn.selected"></td>
                                <td>{{ itemIn.id }}</td>
                                <td>{{ itemIn.name }}</td>
                                <td>{{ itemIn.price }}</td>
                                <td>
                                    <button @click="handleReduce(indexOut,indexIn)" :disabled="itemIn.count === 1">-</button>
                                    {{ itemIn.count }}
                                    <button @click="handleAdd(indexOut,indexIn)">+</button>
                                </td>
                                <td><button @click="handleRemove(indexOut,indexIn)">移除</button></td>
                        </tr>
                    </template>
                </tbody>
            </table>
            <div>总价：￥ {{ totalPrice }}</div>
        </template>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="index.js"></script>
</body>
</html>